
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region ProductDAL
	public class ProductDAL : DBContext
	{
		public List<Product> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_ProductsSelectAll");
            return GetEntityList<Product>(cmd);
        }

        public Product GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_ProductSelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<Product>(cmd);
        }

		public List<Product> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_ProductSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<Product>(cmd);
        }

        public Product Add(string paramCode, string paramName, string paramPhysicalBarcode, string paramPackBarcode,
                                  string paramDescription, Guid paramCategoryId, Guid paramPhysicalUnitId, Guid paramPackUnitId, decimal paramNumberPerPhysical,
                                  decimal paramPhysicalSalePrice, decimal paramPackSalePrice, string paramCreatedBy, int paramStatus)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_ProductInsert");
            cmd.AddParameter("@Code", paramCode);
            cmd.AddParameter("@Name", paramName);
            cmd.AddParameter("@PhysicalBarcode", paramPhysicalBarcode);
            cmd.AddParameter("@PackBarcode", paramPackBarcode);
            cmd.AddParameter("@Description", paramDescription);
            cmd.AddParameter("@CategoryId", paramCategoryId);
            cmd.AddParameter("@PhysicalUnitId", paramPhysicalUnitId);
            cmd.AddParameter("@PackUnitId", paramPackUnitId);
            cmd.AddParameter("@NumberPerPhysical", paramNumberPerPhysical);
            cmd.AddParameter("@PhysicalSalePrice", paramPhysicalSalePrice);
            cmd.AddParameter("@PackSalePrice", paramPackSalePrice);
            cmd.AddParameter("@CreatedBy", paramCreatedBy);
            cmd.AddParameter("@Status", paramStatus);
            return GetSingleEntity<Product>(cmd);
        }
		
        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_ProductDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public Product UpdateById(Guid paramId, string paramCode, string paramName, string paramPhysicalBarcode, string paramPackBarcode,
                                  string paramDescription, Guid paramCategoryId, Guid paramPhysicalUnitId, Guid paramPackUnitId, decimal paramNumberPerPhysical,
                                  decimal paramPhysicalSalePrice, decimal paramPackSalePrice, string paramUpdatedBy, int paramStatus)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_ProductUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@Code", paramCode);
			cmd.AddParameter("@Name", paramName);
			cmd.AddParameter("@PhysicalBarcode", paramPhysicalBarcode);
			cmd.AddParameter("@PackBarcode", paramPackBarcode);
			cmd.AddParameter("@Description", paramDescription);
			cmd.AddParameter("@CategoryId", paramCategoryId);
			cmd.AddParameter("@PhysicalUnitId", paramPhysicalUnitId);
			cmd.AddParameter("@PackUnitId", paramPackUnitId);
			cmd.AddParameter("@NumberPerPhysical", paramNumberPerPhysical);
			cmd.AddParameter("@PhysicalSalePrice", paramPhysicalSalePrice);
			cmd.AddParameter("@PackSalePrice", paramPackSalePrice);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return GetSingleEntity<Product>(cmd);
        }
		
	}
	#endregion
}
